package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Person p = new Person("李四");
        System.out.println(p);
        Class c = Class.forName("reflect.Person");
        Constructor constructor1 = c.getConstructor(String.class);
        Object o = constructor1.newInstance("梨花");

        Constructor constructor2 = c.getConstructor(String.class, int.class);
        Object o2 = constructor2.newInstance("李华", 11);
        System.out.println(o2);
        System.out.println(o);
    }
}
